﻿using StarryEdge.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StarryEdge.Module.Parameter
{
    public abstract class InitFileBase
    {
        protected string _path;
        protected StarryEdge.Core.IStarryEdgeLog _log;
        public InitFileBase(StarryEdge.Core.IStarryEdgeLog log, string directory, string filename)
        {
            _log = log;
            var device_path = Path.Combine(Environment.CurrentDirectory, directory);
            _path = Path.Combine(device_path, filename);
            if (!Directory.Exists(device_path))
            {
                Directory.CreateDirectory(device_path);
            }
        }

        protected string Read()
        {
            return File.ReadAllText(_path, Encoding.UTF8);
        }

        protected bool Save(string value)
        {
            File.WriteAllText(_path, value, Encoding.UTF8);
            return true;
        }
    }
}
